package org.xinghai.sql.main.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xinghai.sql.common.api.Result;
import org.xinghai.sql.main.dto.CreateColumnDto;
import org.xinghai.sql.main.dto.UpdateColumnDto;
import org.xinghai.sql.main.generator.domain.ColumnElements;
import org.xinghai.sql.main.generator.domain.TableColumns;
import org.xinghai.sql.main.generator.service.ColumnElementsService;
import org.xinghai.sql.main.generator.service.TableColumnsService;


/**
 * 表列信息的增删改查
 * @author lijia
 * &#064;date  2025/07/28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/database")
public class TableColumnsController {

   @Autowired
   private TableColumnsService tableColumnsService;

    /**
     * 创建列   必须填写列关键信息
     * @param createColumnDto
     * @return {@link Result }<{@link String }>
     */
    @PostMapping("/createColumn")
    public Result<String> createColumn(
            @RequestBody CreateColumnDto createColumnDto
    ) {
        tableColumnsService.createColumn(createColumnDto);
        return Result.success("创建列成功");
    }
    /**
     * 删除列   必须填写列ID
     * @param columnId
     * @return {@link Result }<{@link String }>
     */
    @DeleteMapping("/deleteColumn")
    public Result<String> deleteColumn(
           @RequestParam("columnId") Long columnId
    ) {
        tableColumnsService.removeById(columnId);
        return Result.success("删除列成功");
    }
    /**
     * 更新列   必须填写列关键信息，且更新的列不可以更新到其他数据库表中
     * @param updateColumnDto
     * @return {@link Result }<{@link String }>
     */
    @PostMapping ("/updateColumn")
    public Result<String> updateColumn(
            @RequestBody UpdateColumnDto updateColumnDto
    ) {
        tableColumnsService.updateColumn(updateColumnDto);
        return Result.success("更新列成功");
    }
}
